package com.kingdee.eas.cp.bc.loan;

import org.springframework.ui.ModelMap;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.eventbus.event.action.KDActionEvent;
import com.kingdee.bos.webframework.exception.WafException;
import com.kingdee.bos.webframework.dynamic.application.WebSymbolConstant;
import com.kingdee.bos.webframework.dynamic.handler.AbstractWebEventHandler;
import com.kingdee.bos.eventbus.event.action.IActionEventHandler;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.cp.bc.DailyLoanBillFactory;
import com.kingdee.eas.cp.bc.DailyLoanBillInfo;
import com.kingdee.eas.custom.cost.BorrowingType;

public class SaveActionEvent extends AbstractWebEventHandler implements IActionEventHandler {
	public void onAction(KDActionEvent event) throws WafException,BOSException {
		ModelMap modelMap = event.getReqeustContext().get(
				ModelMap.class);
		DailyLoanBillInfo model = (DailyLoanBillInfo) modelMap.get(WebSymbolConstant.MODEL_ATTRIBUTE_KEY);
		String[] splits=model.getNumber().split("-");
		String borrowingType = model.getString("borrowingType");
		String name=BorrowingType.getEnum(borrowingType).getName();
		if(splits.length==2){
			model.setNumber(splits[0]+"-"+name+"-"+splits[1]);
		}else if(splits.length==3){
			model.setNumber(splits[0]+"-"+name+"-"+splits[2]);
		}
		SelectorItemCollection sic=new SelectorItemCollection();
		sic.add(new SelectorItemInfo("number"));
		try {
			DailyLoanBillFactory.getRemoteInstance().updatePartial(model, sic);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}
}